package org.example.topicExchange;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author 望轩
 * @createDate 2024/7/4 16:23
 */
@Component
public class NewsProducer {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    public void sendNews(String newsType, String newsJson) {
        rabbitTemplate.convertAndSend("news.exchange", newsType + ".news", newsJson);
        System.out.println("Sent news: " + newsJson);
    }
}